home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / PushbackInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.8 KB  |  138 lines

  1. package java.io;
  2.  
  3. public class PushbackInputStream extends FilterInputStream {
  4.    protected byte[] buf;
  5.    protected int pos;
  6.  
  7.    private void ensureOpen() throws IOException {
  8.       if (this.in == null) {
  9.          throw new IOException("Stream closed");
  10.       }
  11.    }
  12.  
  13.    public PushbackInputStream(InputStream var1, int var2) {
  14.       super(var1);
  15.       if (var2 <= 0) {
  16.          throw new IllegalArgumentException("size <= 0");
  17.       } else {
  18.          this.buf = new byte[var2];
  19.          this.pos = var2;
  20.       }
  21.    }
  22.  
  23.    public PushbackInputStream(InputStream var1) {
  24.       this(var1, 1);
  25.    }
  26.  
  27.    public int read() throws IOException {
  28.       this.ensureOpen();
  29.       return this.pos < this.buf.length ? this.buf[this.pos++] & 255 : super.read();
  30.    }
  31.  
  32.    public int read(byte[] var1, int var2, int var3) throws IOException {
  33.       this.ensureOpen();
  34.       if (var1 == null) {
  35.          throw new NullPointerException();
  36.       } else if (var2 >= 0 && var3 >= 0 && var3 <= var1.length - var2) {
  37.          if (var3 == 0) {
  38.             return 0;
  39.          } else {
  40.             int var4 = this.buf.length - this.pos;
  41.             if (var4 > 0) {
  42.                if (var3 < var4) {
  43.                   var4 = var3;
  44.                }
  45.  
  46.                System.arraycopy(this.buf, this.pos, var1, var2, var4);
  47.                this.pos += var4;
  48.                var2 += var4;
  49.                var3 -= var4;
  50.             }
  51.  
  52.             if (var3 > 0) {
  53.                var3 = super.read(var1, var2, var3);
  54.                if (var3 == -1) {
  55.                   return var4 == 0 ? -1 : var4;
  56.                } else {
  57.                   return var4 + var3;
  58.                }
  59.             } else {
  60.                return var4;
  61.             }
  62.          }
  63.       } else {
  64.          throw new IndexOutOfBoundsException();
  65.       }
  66.    }
  67.  
  68.    public void unread(int var1) throws IOException {
  69.       this.ensureOpen();
  70.       if (this.pos == 0) {
  71.          throw new IOException("Push back buffer is full");
  72.       } else {
  73.          this.buf[--this.pos] = (byte)var1;
  74.       }
  75.    }
  76.  
  77.    public void unread(byte[] var1, int var2, int var3) throws IOException {
  78.       this.ensureOpen();
  79.       if (var3 > this.pos) {
  80.          throw new IOException("Push back buffer is full");
  81.       } else {
  82.          this.pos -= var3;
  83.          System.arraycopy(var1, var2, this.buf, this.pos, var3);
  84.       }
  85.    }
  86.  
  87.    public void unread(byte[] var1) throws IOException {
  88.       this.unread(var1, 0, var1.length);
  89.    }
  90.  
  91.    public int available() throws IOException {
  92.       this.ensureOpen();
  93.       return this.buf.length - this.pos + super.available();
  94.    }
  95.  
  96.    public long skip(long var1) throws IOException {
  97.       this.ensureOpen();
  98.       if (var1 <= 0L) {
  99.          return 0L;
  100.       } else {
  101.          long var3 = (long)(this.buf.length - this.pos);
  102.          if (var3 > 0L) {
  103.             if (var1 < var3) {
  104.                var3 = var1;
  105.             }
  106.  
  107.             this.pos = (int)((long)this.pos + var3);
  108.             var1 -= var3;
  109.          }
  110.  
  111.          if (var1 > 0L) {
  112.             var3 += super.skip(var1);
  113.          }
  114.  
  115.          return var3;
  116.       }
  117.    }
  118.  
  119.    public boolean markSupported() {
  120.       return false;
  121.    }
  122.  
  123.    public synchronized void mark(int var1) {
  124.    }
  125.  
  126.    public synchronized void reset() throws IOException {
  127.       throw new IOException("mark/reset not supported");
  128.    }
  129.  
  130.    public synchronized void close() throws IOException {
  131.       if (this.in != null) {
  132.          this.in.close();
  133.          this.in = null;
  134.          this.buf = null;
  135.       }
  136.    }
  137. }
  138.